home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UNIXTOOL / GNU / TILEFORTH / TILE / TILE~ / !Tile / test / sieve / byte next >
Text File  |  1992-04-20  |  1KB  |  44 lines

  1. .( Loading Byte Magazine Sieve benchmark...) cr
  2.  
  3. \ This is the "standard" sieve benchmark as published in Byte Magazine.
  4. \ The algorithm is wrong in the sense that it gives an incorrect count
  5. \ of the number of primes.  That doesn't affect it's usefulness as a
  6. \ benchmark.
  7. \
  8. \ This benchmark tends to be relatively insensitive to the efficiency
  9. \ of "nesting" (calling a colon definition), since it is implemented
  10. \ almost entirely with very low level words, which are code words in
  11. \ most Forth implementations.  This is reasonably fair, however, since
  12. \ studies have shown that in many Forth programs, code words get
  13. \ executed on the order of 8 times more frequently than colon
  14. \ definitions.
  15.  
  16. decimal
  17.  
  18. 8192 constant size ( -- int)
  19. create flags ( -- addr) size allot
  20.  
  21. : do-prime ( -- )
  22.   flags size 1 fill
  23.   0 size 0 do
  24.     flags i + c@
  25.     if i dup + 3 + dup i +
  26.       begin
  27.        dup size <
  28.       while
  29.        0 over flags + c!
  30.        over +
  31.       repeat
  32.       2drop 1+
  33.     then
  34.     (event) process
  35.   loop
  36.   1899 = not abort" prime: wrong result"
  37. ;
  38.  
  39. : byte-sieve ( -- )
  40.   10 0 do do-prime loop
  41. ;
  42.  
  43. forth only
  44.